﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Torrent
{
    public partial class SeverMain : Form
    {
        public SeverMain()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dBDataSet.Files' table. You can move, or remove it, as needed.
            this.filesTableAdapter.Fill(this.dBDataSet.Files);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.filesTableAdapter.Fill(this.dBDataSet.Files);
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 6 && e.RowIndex != dataGridView1.RowCount - 1)
            {
                string address;
                //Form2 f2 = new Form2();
                //f2.cn = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value);
                //f2.st = gStu;
                //f2.id = gStu[f2.cn].stdId;
                //f2.ShowDialog(this);
               // MessageBox.Show("sss");
                saveFileDialog1.DefaultExt = "torrent";
                //saveFileDialog1.FileName = textBox4.Text;
                saveFileDialog1.Filter = "torrent files (*.torrent) |*.*";
                saveFileDialog1.FilterIndex = 1;
                saveFileDialog1.OverwritePrompt = true;
                saveFileDialog1.Title = "ذخیره فابل تورنت";

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {

                    address = saveFileDialog1.FileName;
                    
                    
                    FileStream fs = new FileStream(address, FileMode.Create);
                    StreamWriter sw=new StreamWriter(fs);
                    BinaryWriter br=new BinaryWriter(fs);
                  
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[0].Value);
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[1].Value);
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[2].Value);
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[3].Value);
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[4].Value);
                    sw.WriteLine(dataGridView1.Rows[e.RowIndex].Cells[5].Value);
                   
                    //br.Write("hello\rali");
                   // fs.Write(buffer, 0, buffer.Length);
                    sw.Close();
                    br.Close();
                    fs.Close();

                }
            }
        }
    }
}
